package com.softer.wxzj.common.logic;

import com.softer.wxzj.common.util.StringUtils;
import com.softer.wxzj.entity.BaseHouseInfo;
import com.softer.wxzj.entity.DepModeInfo;
import com.softer.wxzj.service.DepModeInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;

/**
 *    
 *  @ClassName: CalculateAmount
 *  @Description: 计算金额逻辑类
 *  @Author:  zcz
 *  @CreateDate: 2019-05-10   
 */
@Component
public class CalculateAmount {
    @Autowired
    private DepModeInfoService depModeInfoService;

    /**
     * 计算应缴金额
     *
     * @param houseInfo
     * @return
     */
    public BigDecimal calculateDueAmount(BaseHouseInfo houseInfo) {
        return dueAmount(houseInfo, null);
    }

    public BigDecimal calculateDueAmountDep(BaseHouseInfo houseInfo, DepModeInfo depModeInfo) {
        return dueAmount(houseInfo, depModeInfo);
    }

    public BigDecimal dueAmount(BaseHouseInfo houseInfo, DepModeInfo depModeInfo) {
        BigDecimal dueAmount = BigDecimal.ZERO;
        if (StringUtils.isBlank(houseInfo.getFirstMode())) {
            return dueAmount;
        }
        if (null == depModeInfo) {
            depModeInfo = depModeInfoService.getInfo(houseInfo.getFirstMode());
        }
        //TODO 测试完成去掉
        if (depModeInfo == null || StringUtils.isEmpty(depModeInfo.getDepType())) {
            return dueAmount;
        }
        switch (depModeInfo.getDepType()) {
            //售价
            case "1":
                BigDecimal price = null == houseInfo.getPrice() ? BigDecimal.ZERO : houseInfo.getPrice();
                dueAmount = price.multiply(depModeInfo.getRatio());
                break;
            //面积
            case "2":
                dueAmount = houseInfo.getStruArea().multiply(depModeInfo.getRatio());
                break;
            //建安成本
            case "3":
                dueAmount = houseInfo.getStruArea().multiply(depModeInfo.getRatio()).multiply(depModeInfo.getConstructionCost());
                break;
            //制定金额
            case "4":
                dueAmount = depModeInfo.getRatio();
                break;
        }
        return dueAmount;
    }

}
